home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Source Code
/
C
/
Frameworks
/
Grant's CGI Framework 1.0b12
/
Util
/
ListSTAR.c
< prev
next >
Wrap
Text File
|
1995-12-09
|
9KB
|
316 lines
/*****
*
* Grant's CGI Framework
* (Common Grant Interface :-)
* by Grant Neufeld
* http://arpp1.carleton.ca/grant/mac/grantscgi.html
*
* ListSTAR.c
*
* Standard functions for ListSTAR trigger & action applications.
*
* You must call InitListSTARUtil in your application startup.
* You must install ListSTARAEHandle as the event handler for the 9evt9Lis apple event
* You must write the function:
* void MyListSTARProcess ( LStarHdl theLStarHdl )
* which is where you will, guess what, do your application specific processing
* of the ListSTAR stuff.
*
* Do not call any functions begining with lower case 'lstar' - you can use any of the
* others - but read their comments first for details.
*
* watch the homepage for future upgrades
*
* notice of upgrades will be posted to macwwwtool@arpp1.carelton.ca
* see http://arpp1.carleton.ca/list/macwwwtool.html for details
*
*
* Copyright ©1995 by Grant Neufeld
*
* http://arpp1.carleton.ca/grant/
* gneufeld@ccs.carleton.ca
* grant@acm.org
*
* This source may be freely used as long as the copyright notice is kept in the source.
* I ask that you let me know of any enhancements (read: bug fixes) to this code.
* I would also like copies of (or discounts on) anything you produce this with, please.
*
* See the License and Limited Warranty Agreement for all the legal stuff.
*
*****/
#include "MyConfiguration.h"
#if kCompileWithListSTARCode
#include <string.h>
#include "compiler_stuff.h"
#include "globals.h"
#include "AEFunc.h"
#include "DebugUtil.h"
#include "MemoryUtil.h"
#include "StringUtil.h"
/* ListSTAR.h processes differently for ListSTAR.c,
this is controlled by defining __LStarSegment__ */
#define __LStarSegment__ 1
#include "ListSTAR.h"
#undef __LStarSegment__
/*** CONSTANT DECLARATIONS ***/
/*** LOCAL FUNCTION PROTOTYPES ***/
static void lstarDisposeHandle ( LStarHdl );
static OSErr lstarAEGetParamSpoolFile ( AppleEvent *, AEKeyword, FSSpec *, char *, long );
/*** FUNCTIONS ***/
/* This initialization function MUST be called in the startup sequence of
your application */
OSErr
InitListSTARUtil ( void )
{
OSErr theErr;
AEEventHandlerUPP theUPP;
StringHandle liststarSpoolPath;
/* install the ListSTAR apple event handler */
theUPP = NewAEEventHandlerProc ( ListSTARAppleEvent );
theErr = AEInstallEventHandler ( kAEClassStarNine, kAEIDListStarEvent, theUPP, 0L, false );
if ( theErr != noErr )
{
/* liststar AE install failed */
return theErr;
}
liststarSpoolPath = GetString ( krsListSTARSpoolPath );
if ( liststarSpoolPath != nil )
{
HLock ( (Handle)liststarSpoolPath );
/* locate ListSTAR's mail spool folder and set up it's FSSpec.
OSErr returned ignored */
theErr = FSMakeFSSpec ( nil, nil, *liststarSpoolPath, &gListSTARSpoolFolder );
HUnlock ( (Handle)liststarSpoolPath );
ReleaseResource ( (Handle)liststarSpoolPath );
}
return theErr;
} /* InitListSTARUtil */
#pragma mark -
/* */
static void
lstarDisposeHandle ( LStarHdl theLStarHdl )
{
my_assert ( theLStarHdl != nil, "\plstarDisposeHandle: theLStarHdl is nil" );
if ( (*theLStarHdl)->mailService != nil )
{
DisposePtr ( (Ptr)((*theLStarHdl)->mailService) );
}
if ( (*theLStarHdl)->senderName != nil )
{
DisposePtr ( (Ptr)((*theLStarHdl)->senderName) );
}
if ( (*theLStarHdl)->senderEmail != nil )
{
DisposePtr ( (Ptr)((*theLStarHdl)->senderEmail) );
}
if ( (*theLStarHdl)->mailSubject != nil )
{
DisposePtr ( (Ptr)((*theLStarHdl)->mailSubject) );
}
if ( (*theLStarHdl)->regExp != nil )
{
DisposePtr ( (Ptr)((*theLStarHdl)->regExp) );
}
if ( (*theLStarHdl)->senderMC != nil )
{
DisposePtr ( (Ptr)((*theLStarHdl)->senderMC) );
}
if ( (*theLStarHdl)->senderMCZone != nil )
{
DisposePtr ( (Ptr)((*theLStarHdl)->senderMCZone) );
}
if ( (*theLStarHdl)->senderMCEmail != nil )
{
DisposePtr ( (Ptr)((*theLStarHdl)->senderMCEmail) );
}
DisposeHandle ( (Handle)theLStarHdl );
} /* lstarDisposeHandle */
/** APPLE EVENT SUPPORT **/
#pragma mark -
#pragma segment AppleEvents
/* AppleEvent Handler for the ListSTAR 9evt-9Lis event */
pascal OSErr
ListSTARAppleEvent ( AppleEvent *theAppleEvent, AppleEvent *TheReply, long Reference )
{
OSErr theErr;
// DescType actualType;
Ptr tempBuffer;
LStarHdl theLStarHdl;
theLStarHdl = (LStarHdl) MyNewHandleClear ( sizeof(LStarRecord), &theErr );
if ( theLStarHdl == nil )
{
return theErr;
}
/* store references to the apple event and reply records */
(*theLStarHdl)->appleEvent = theAppleEvent;
(*theLStarHdl)->replyEvent = TheReply;
tempBuffer = MyNewPtr ( kLStarParamMaxSize, &theErr );
if ( tempBuffer == nil )
{
DisposeHandle ( (Handle)theLStarHdl );
return theErr;
}
// actualType = (DescType) 'char';
HLockHi ( (Handle)theLStarHdl );
/* '----' - direct parameter: mailService */
theErr = AEGetParamString ( theAppleEvent, kLSTARmailService, &((*theLStarHdl)->mailService),
(char *)tempBuffer, kLStarParamMaxSize );
/* 's9nm' - senderName */
theErr = AEGetParamString ( theAppleEvent, kLSTARsenderName, &((*theLStarHdl)->senderName),
(char *)tempBuffer, kLStarParamMaxSize );
/* 's9em' - senderEmail */
theErr = AEGetParamString ( theAppleEvent, kLSTARsenderEmail, &((*theLStarHdl)->senderEmail),
(char *)tempBuffer, kLStarParamMaxSize );
/* 's9sj' - mailSubject */
theErr = AEGetParamString ( theAppleEvent, kLSTARmailSubject, &((*theLStarHdl)->mailSubject),
(char *)tempBuffer, kLStarParamMaxSize );
/* 's9re' - regExp */
theErr = AEGetParamString ( theAppleEvent, kLSTARregExp, &((*theLStarHdl)->regExp),
(char *)tempBuffer, kLStarParamMaxSize );
/* 's9fn' - mailFile */
theErr = lstarAEGetParamSpoolFile ( theAppleEvent, kLSTARmailFile, &((*theLStarHdl)->mailFile),
(char *)tempBuffer, kLStarParamMaxSize );
/* 's9mc' - senderMC */
theErr = AEGetParamString ( theAppleEvent, kLSTARsenderMC, &((*theLStarHdl)->senderMC),
(char *)tempBuffer, kLStarParamMaxSize );
/* 's9mz' - senderMCZone */
theErr = AEGetParamString ( theAppleEvent, kLSTARsenderMCZone, &((*theLStarHdl)->senderMCZone),
(char *)tempBuffer, kLStarParamMaxSize );
/* 's9me' - senderMCEmail */
theErr = AEGetParamString ( theAppleEvent, kLSTARsenderMCEmail, &((*theLStarHdl)->senderMCEmail),
(char *)tempBuffer, kLStarParamMaxSize );
/* don't need the buffer any more */
DisposePtr ( tempBuffer );
/* ••• need to add "MyAEGotRequiredParams" here */
/* don't know how to determine difference between action and trigger yet,
so default to trigger. This can be changed to action by the
'MyListSTARProcess' function */
(*theLStarHdl)->method = ListSTAR_Trigger;
/* allocate triggerValue */
(*theLStarHdl)->triggerValue = (long *) MyNewPtr ( sizeof(long), nil );
if ( (*theLStarHdl)->triggerValue != nil )
{
/* default to failure unless the 'MyListSTARProcess' function determines success or error */
*((*theLStarHdl)->triggerValue) = Trigger_failure;
}
/* this is where the application specific ListSTAR event handling comes into play
the function "MyListSTARProcess" must be provided by the user of
this source code */
HUnlock ( (Handle)theLStarHdl );
MyListSTARProcess ( theLStarHdl );
HLock ( (Handle)theLStarHdl );
if ( ((*theLStarHdl)->method == ListSTAR_Trigger) &&
((*theLStarHdl)->triggerValue != nil) )
{
/* if the event is a trigger, return the trigger value */
theErr = AEPutParamPtr ( TheReply, keyDirectObject, typeLongInteger,
(Ptr)((*theLStarHdl)->triggerValue), sizeof(long) );
}
else
{
/* otherwise, don't return any data */
theErr = noErr;
}
HUnlock ( (Handle)theLStarHdl );
/* deallocate memory */
lstarDisposeHandle ( theLStarHdl );
return theErr;
} /* ListSTARAppleEvent */
#pragma segment AppleEvents
/* private function to get an HTTPMethod from a parameter */
static OSErr
lstarAEGetParamSpoolFile ( AppleEvent *theAppleEvent, AEKeyword theAEKeyword, FSSpec *theFile, char *tempBuffer, long bufferSize )
{
OSErr theErr;
DescType actualType;
Size actualSize;
my_assert ( theFile != nil, "\plstarAEGetParamSpoolFile: theFile ptr is nil" );
my_assert ( theAppleEvent != nil, "\plstarAEGetParamSpoolFile: theAppleEvent ptr is nil" );
my_assert ( tempBuffer != nil, "\plstarAEGetParamSpoolFile: tempBuffer ptr is nil" );
/* put the message spool file name into the tempBuffer */
theErr = AEGetParamPtr
( theAppleEvent, theAEKeyword, typeChar, &actualType, (Ptr)tempBuffer, bufferSize - 1, &actualSize );
if ( theErr == noErr )
{
my_assert ( actualSize < bufferSize, "\plstarAEGetParamSpoolFile: actual param size too big" );
/* terminate the buffer with a null byte, making it a C format string */
tempBuffer[actualSize] = nil;
/* convert to pascal format string */
C2PStr ( tempBuffer );
/* make an fsspec using the mail spool directory and the tempBuffer as file name */
theErr = FSMakeFSSpec ( gListSTARSpoolFolder.vRefNum,
gListSTARSpoolFolder.parID, (StringPtr)tempBuffer, theFile );
}
return theErr;
} /* lstarAEGetParamHTTPMethod */
#endif /* kCompileWithListSTARCode */
/*** EOF ***/